home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_gen_aiframepatrol.cog < prev    next >
Text File  |  1999-11-15  |  3KB  |  133 lines

  1. # Jones 3D Cog Script
  2. #
  3. # 00_AIFramePatrol.cog
  4. # "patroller" travels patrol route of frames.
  5. # Patrol begins at startup unless either gosector or gosurface are assigned as triggers.
  6. # Compatible with 00_SendMessage. (Gosurface or gosector must be assigned or it will begin on startup.)
  7. #
  8. # Flex Variables:
  9. #
  10. # RouteStyle: use 0 for circular (or 2-point) patrol, 1 for linear, and 2 for random
  11. # FramePause: use a constant value, or use 0 for random pauses between 2 and Maxpause (best for pedestrians)
  12. # NumFrames: number of frames in the route, excluding frame 0; NOTE: Inaccurately high framenum results in 1-way patrol
  13. # PatrolSpeed: 1 for walk (default), 2 for run
  14. # MaxPause: longest pause at frame, used only if framepause = 0
  15. #
  16. # [RD]
  17. #
  18. # (C) 1997 LucasArts Entertainment Co. All Rights Reserved
  19. # ========================================================================================
  20.  
  21. symbols
  22.     message    startup
  23.     message    activate
  24.     message    entered
  25.     message    arrived
  26.     message    timer
  27.  
  28.     sector    gosector        linkid=1
  29.     surface    gosurface    linkid=1
  30.  
  31.     thing        patroller
  32.  
  33.     flex        patrolspeed=1.0
  34.     flex        framepause=1.0
  35.     flex        routestyle=0.0
  36.     flex        numframes=1.0
  37.     flex        maxpause=10.0
  38.     
  39.     # ** subroutines **
  40.     flex        beginpatrol local
  41.  
  42.     int        curframe=1        local
  43.     int        framenum=0        local
  44.     int        direction=1        local        // control forward or backward through frames
  45.     int        begun=0            local
  46.     int        testnum=0        local
  47. end
  48.  
  49. # ========================================================================================
  50.  
  51. code
  52. startup:
  53.     if (gosector + gosurface == -2)    // no sector/surface assigned
  54.     {
  55.         call beginpatrol;
  56.     }
  57.     return;
  58.  
  59. # ........................................................................................
  60.  
  61. activate:
  62.     call beginpatrol;
  63.     return;
  64.  
  65. # ........................................................................................
  66.  
  67. entered:
  68.     if (GetSenderID() != 1) return;
  69.     
  70.     call beginpatrol;
  71.     return;
  72.     
  73. # ........................................................................................
  74.  
  75. beginpatrol:
  76.     if (begun) return;
  77.     begun = 1;
  78.     
  79.     AISetMoveSpeed(patroller, patrolspeed);
  80.     
  81.     SetTimer(.1);
  82.     return;
  83.  
  84. # ........................................................................................
  85.  
  86. arrived:
  87.     curframe = curframe + direction;
  88.     if (curframe > numframes)            // end of patrol
  89.     {
  90.         if (routestyle == 1)
  91.         {
  92.             direction = -1;            // if linear, reverse frame directional
  93.             curframe = numframes - 1;
  94.         }
  95.         else
  96.         {
  97.             curframe = 0;            // if circular, go to frame 0
  98.         }
  99.     }
  100.  
  101.     if ((curframe == -1) && (routestyle == 1))    // if linear and returned to initial frame
  102.     {
  103.         direction = 1;                    // restore forward frame directional
  104.         curframe = 1;                    // small bug fixed by Tim L., changed from 0 to 1
  105.     }
  106.  
  107.     if (routestyle == 2)
  108.     {
  109.         curframe = (Rand() * numframes) + 1;
  110.     }
  111.  
  112.     if (framepause > 0)
  113.     {
  114.         SetTimer(framepause);
  115.     }
  116.     else
  117.     {
  118.         SetTimer((Rand() * (maxpause - 1)) + 2);
  119.     }
  120.     return;
  121.  
  122. # ........................................................................................
  123.  
  124. timer:
  125.     AISetLookFrame(patroller, curframe);
  126.     AISetMoveFrame(patroller, curframe);
  127.     return;
  128.  
  129. # ........................................................................................
  130.  
  131. end
  132.  
  133.